package com.swc.user.controller;

import com.swc.user.pojo.User;
import com.swc.user.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author songwc
 * @date 2020/5/30 11:25
 */
@RestController
@RequestMapping("user")
public class UserController {

    Logger logger = LoggerFactory.getLogger(UserController.class);

    @Autowired
    private UserService userService;

    @GetMapping("/{id}")
    public User queryById(@PathVariable("id") Long id)
    {
        return this.userService.getById(id);
    }

    /**
     * POSTMAN 请求
     *
     * curl --location --request GET 'http://127.0.0.1:10010/user-service/user/hello?request=Jfv66kO3Uqg6NwYfJuc6sA==' \
     * --header 'encrypt-mode: 3' \
     * --header 'resp-encrypt: 1' \
     * --header 'url-param-decrypt: 1' \
     * --header 'secret-key: DoEUpCphRv6h2BVZCVEDrndOm8awzytWHqhLbsbzhBKUGdiQfyVwrk3Evmk+l3wM4y5J3t7bkmCdqKh/Bj97c+A35vlRUC35MKDSOyPMr3tYfyKJlQQIUJV+Ros1ZQlCHiDjmWYD73+WdktpLVnAUlEyYDVQI9kihID9z5crvM4=' \
     * --header 'sign: ec079b893b6695cdeb822405b0938fb5ce7094de4a3b9919aa49ba31b6dd657d' \
     * --header 'Content-Type: application/x-www-form-urlencoded'
     *
     * @param name
     * @return
     */
    @GetMapping("/hello")
    public String hello(@RequestParam("name") String name) {
        logger.info("name: {}", name);
        return name;
    }

    /**
     * POSTMAN 请求
     *
     * curl --location --request POST 'http://127.0.0.1:10010/user-service/user/sayHello' \
     * --header 'encrypt-mode: 3' \
     * --header 'secret-key: DoEUpCphRv6h2BVZCVEDrndOm8awzytWHqhLbsbzhBKUGdiQfyVwrk3Evmk+l3wM4y5J3t7bkmCdqKh/Bj97c+A35vlRUC35MKDSOyPMr3tYfyKJlQQIUJV+Ros1ZQlCHiDjmWYD73+WdktpLVnAUlEyYDVQI9kihID9z5crvM4=' \
     * --header 'sign: 9d729404f67e94ab2c64e30c36629dff7823e6df603480a77b9a6933b262d583' \
     * --header 'Content-Type: application/json' \
     * --data-raw '{"request":"Bo086OF6hnYUYJ8sIJPwwK69+ObyBgYSEmg4ZHzJfms="}'
     *
     * @param user
     */
    @PostMapping("/sayHello")
    public void sayHello(@RequestBody User user) {
        logger.info("user: {}", user);
    }
}
